<?php foreach ($edit_data as $key): ?>
		<div class="ibox float-e-margins">
			<div class="ibox-title" style="border: none;">
				<h5 style="color: #00afef"><i>Edit</i></h5>
				<div class="ibox-tools">
					<button class="btn btn-sm btn-primary save-btn-tab" id="saveEditForm">Save</button>
					<button class="btn btn-sm btn-primary btn-outline close-edit cancel-btn-tab">Cancel</button>
				</div>
			</div>
			<div class="ibox-content">
				<form class="form-horizontal" id="form-forms-edit">
					<div class="form-group">
						<label class="col-lg-4 control-label">Code</label>
						<input type="hidden" value="<?php echo $key->form_id; ?>" name="form_id_e">
						<div class="col-lg-3">
							<input readonly value="<?php echo $key->form_code; ?>" name="form_code_e" type="text" class="form-control">
						</div>
					</div>
					<div class="form-group">
						<label class="col-lg-4 control-label">Name</label>
						<div class="col-lg-5">
							<input value="<?php echo $key->form_name; ?>" type="text" name="form_name_e" class="form-control">
						</div>
					</div>
					<div class="form-group">
						<label class="col-lg-4 control-label">Description</label>
						<div class="col-lg-5">
							<input type="text" value="<?php echo $key->description; ?>" name="form_desc_e" class="form-control">
						</div>
					</div>
					<div class="form-group">
                        <label class="col-lg-4 control-label">Program Type</label>
                        <div class="col-lg-5">
                           <select class="form-control m-b" name="prog_type_e" id ="prog_type">
                                <option value="" id="empty-option">--</option>
                                <?php foreach($prog_type as $p): ?>
                                <option value="<?php echo $p->lookup_code; ?>" <?php echo ($key->program_type == $p->lookup_code ? 'selected' : ''); ?>><?php echo $p->meaning; ?></option>
                                <?php endforeach ?>
                            </select>
                        </div>
                    </div>
					<div class="form-group">
						<label class="col-lg-4 control-label">Module</label>
						<div class="col-lg-5">
							<input type="hidden" name="module_id_hidden" value="<?php echo $key->module_id; ?>">
							<select class="form-control m-b" name="module_id_e" id ="module_option_e">
								<option value="" id="empty-option">Select Module</option>
								<?php foreach ($mods as $m) {?>
								<option value ="<?php echo $m->module_id; ?>" <?php echo ($key->module_id == $m->module_id) ? 'selected' : ''; ?>><?php echo $m->module_name; ?></option>
								<?php }
?>
							</select>
						</div>
					</div>
					<script type="text/javascript">
					</script>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Module Menu</label>
                        <input type="hidden" id="mod_menu_id_hidden" value="<?php echo $key->menu_id; ?>">
                        <div class="col-lg-5">
                            <select class="form-control m-b" name="mod_menu_id_e" id ="module_menu_option_e">
                                <option value="" id="empty-option">Select Module Menu</option>
                            </select>
                        </div>
                    </div>
					<div class="form-group">
						<label class="col-lg-4 control-label">Executable Filename</label>
						<div class="col-lg-5">
							<input type="text" name="form_exe_name_e" value="<?php echo $key->exe_file_name; ?>" class="form-control">
						</div>
					</div>
					<div class="form-group">
						<label class="col-lg-4 control-label">Enable</label>
						<div class="col-lg-1">
							<input <?php echo ($key->enable_flag == 'Y' ? 'checked' : ''); ?> type="checkbox" class="i-checks" value="ok" name="form_enabler_e">
						</div>
					</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<?php endforeach;?>
	<script type="text/javascript">
	$(document).ready(function() {
		$('select').chosen({width: '100%'});
		$.ajax({
	        type: "POST",
	        url: "<?php echo base_url($this->session->userdata('forajax') . '/searchmodmenu'); ?>",
	        data: { "mod_menu_id" :  $('#module_option_e').val() },
	        dataType: 'json',
	        success: function(e){
	           console.log(e);
                var tmp = "";
                var id = $('#mod_menu_id_hidden').val();
                $.each(e, function(i, item) {
                	var selected = '';
                	if(e[i].menu_id == id){
                		selected = "selected";
                	}
                    tmp += "<option value='"+e[i].menu_id+"' "+selected+">"+e[i].menu_name+"</option>";
                });
                tmp = tmp + "<option value='-1'>None</option>";
                 $('#module_menu_option_e').html(tmp);
                 $('select').trigger('chosen:updated');
	        }
        });
		$('#module_option_e').change(function(){
            var id = $('#module_option_e').val();
            console.log(id);
            $.ajax({
            type: "POST",
            url: "<?php echo base_url($this->session->userdata('forajax') . '/searchmodmenu'); ?>",
            data: { "mod_menu_id" : id },
            dataType: 'json',
            success: function(e){
                console.log(e);
                var tmp = "";
                var id = $('#mod_menu_id_hidden').val();
                $.each(e, function(i, item) {
                	var selected = '';
                	if(e[i].menu_id == id){
                		selected = "selected";
                	}
                    tmp += "<option value='"+e[i].menu_id+"' "+selected+">"+e[i].menu_name+"</option>";
                });
                tmp = tmp + "<option value='-1'>None</option>";
                 $('#module_menu_option_e').html(tmp);
                 $('select').trigger('chosen:updated');
            }
            });
        });

		$('.i-checks').iCheck({
	        checkboxClass: 'icheckbox_square-green',
	        radioClass: 'iradio_square-green'
	    });
	    $("#form-forms-edit").validate({
                 rules: {
                     form_name_e: {
                        required: true
                     },
                     form_desc_e: {
                        required : true
                     },
                     module_id_e: {
                        required: true
                     }
                 }
        });
        $('#saveEditForm').click(function(){
        	if($("#form-forms-edit" ).valid() == true){
            $.ajax({
                url: "<?php echo base_url($this->session->userdata('forajax') . '/editForm'); ?>",
                method:'post',
                data:$('#form-forms-edit').serialize(),
                dataType:'json',
                success: function (data) {
                    var text = data.msg;
                    var term = "exists";
                    console.log(text);
                    if(data.msg === "<p>You did not select a file to upload.</p>" || data.msg === "<p>The filetype you are attempting to upload is not allowed.</p>"){
                        notifymsg('danger','<b>Error:</b> '+data.msg);
                    }else if(text === null){
                            $('#add-link').remove();
                            $('#add').remove();
                            $('#tab-list a:first').tab('show');
                            $('#count_add').val('0');
                            notifymsg('success','<b>Success</b>: Data saved.');
                    }else if(text.indexOf(term) !== -1){
                            $('#err-msg').html(data.msg);
                            notifymsg('danger','<b>Error</b>: '+data.msg);
                    }else{

                    }
                },
                complete: function() {
                    $("#saveForm").removeAttr("disabled");
                },
                beforeSend: function(){
                    $("#saveForm").attr("disabled", true);
                }
            });
			}
		});
	});
	</script>